package com.snake.springboot.authority.web.controller;

import com.snake.springboot.authority.api.model.AuthStrategyMenuModel;
import com.snake.springboot.authority.api.request.AuthStrategyMenuQuery;
import com.snake.springboot.authority.api.request.AuthStrategyMenuSave;
import com.snake.springboot.authority.api.response.AuthMenuRsp;
import com.snake.springboot.authority.api.service.AuthStrategyMenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.snake.common.result.ResponseResult;
import org.snake.common.result.ResponseResultFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 类 {@code AuthStrategyMenuController}  <br> .
 * <p>权限策略与菜单关系控制器
 * <p>创建时间：2025/02/08
 *
 * @author Huang.yj
 */
@Api(tags = "权限管理-权限策略与菜单关系")
@RestController
@RequestMapping("/auth/strategy-menu")
public class AuthStrategyMenuController {

    private AuthStrategyMenuService authStrategyMenuService;

    @Autowired
    public AuthStrategyMenuController(AuthStrategyMenuService authStrategyMenuService){
        this.authStrategyMenuService = authStrategyMenuService;
    }

    @ApiOperation("查询权限策略与菜单关系")
    @PostMapping("/list")
    public ResponseResult<List<AuthStrategyMenuModel>> queryAuthStrategyMenuRef(
            @ApiParam(name = "权限策略与菜单关系入参", value = "传入json格式", required = true)
            @RequestBody AuthStrategyMenuModel model){
        List<AuthStrategyMenuModel> result = authStrategyMenuService.queryAuthStrategyMenuRef(model);
        return ResponseResultFactory.ucc("查询成功",result);
    }

    @ApiOperation("保存权限策略与菜单关系")
    @PostMapping("/add")
    public ResponseResult<Object> saveStrategyMenuRef(
            @ApiParam(name = "权限策略与菜单关系保存入参", value = "传入json格式", required = true)
            @RequestBody AuthStrategyMenuSave params){
        authStrategyMenuService.saveStrategyMenuRef(params);
        return ResponseResultFactory.ucc("保存成功");
    }

    @ApiOperation("查询树型权限策略与菜单关系")
    @PostMapping("/tree")
    public ResponseResult<List<AuthMenuRsp>> queryAuthMenuTree(
            @ApiParam(name = "权限策略与菜单关系查询入参", value = "传入json格式", required = true)
            @RequestBody AuthStrategyMenuQuery params){
        List<AuthMenuRsp> result = authStrategyMenuService.queryAuthMenuTree(params);
        return ResponseResultFactory.ucc("查询成功",result);
    }
}
